package com.woniu.controller;


import com.woniu.commons.Result;
import com.woniu.controller.form.CheckList;
import com.woniu.controller.form.ProductForm;
import com.woniu.model.Page;
import com.woniu.service.IEProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 拍品表 前端控制器
 * </p>
 *
 * @author Kevin Kwok
 * @since 2021-04-16
 */
@RestController
@RequestMapping("/product")
public class EProductController {
    @Resource
    private IEProductService productService;

    @RequiresPermissions({"拍品管理"})
    @GetMapping("/showAll")
    public Result shoWAll(Page page){
        //获取当前页的信息
        List<ProductForm> productForms = productService.showAllCurrent(page.getPageIndex(), page.getPageSize());
        //获得分页的数据
        Page pageInfo = productService.getPageInfo(page.getPageIndex(), page.getPageSize());


        return new Result("200","success",pageInfo,productForms);
    }

    @RequiresPermissions({"拍品管理"})
    @GetMapping("/check")
    public Result checkShops(){
        List<CheckList> checkLists = productService.queryAll();

        return new Result("200","success",null,checkLists);
    }

    @RequiresPermissions({"拍品管理"})
    @GetMapping("/pass/{pid}")
    public Result checkPass(@PathVariable("pid") int pid){
        int i = productService.checkPass(pid);
        if(i==0){
            return new Result("400","修改失败",null,null);

        }
        return new Result("200","修改成功",null,null);
    }

    @RequiresPermissions({"拍品管理"})
    @GetMapping("/refuse/{pid}")
    public Result checkRefuse(@PathVariable("pid") int pid){
        int i = productService.checkRefuse(pid);
        if(i==0){
            return new Result("400","修改失败",null,null);

        }
        return new Result("200","修改成功",null,null);
    }
}

